const date = require('../../../utils/util')
Page({
  data:{
    currentId:'',
    // 最新推荐
  recommendData:[],
  infoData:{},
  date:'',
  likeIcon:'like-o',
  zanIcon:'thumb-circle-o',
  action1:'add',
  action2:'add'
  },
  
  onLoad: function (option) {
    this.setData({currentId:option.id})
    this.getNewData(this.data.currentId)
  
  },
  // 收藏
 async btnLike(){
     await wx.http.get('/user/userDataHandle',{
      article_id:this.data.currentId,
      type:'1',
      action:this.data.action1
    })
    if(this.data.likeIcon === 'like-o'){
      this.setData({action1:'del'})
      this.setData({likeIcon:'like'})
    }else{
      this.setData({action1:'add'})
      this.setData({likeIcon:'like-o'})
    }
  },
  // 点赞
 async btnZan(){
    await wx.http.get('/user/userDataHandle',{
      article_id:this.data.currentId,
      type:'2',
      action:this.data.action2
    })
    if(this.data.zanIcon ==='thumb-circle-o'){
      this.setData({action2:'del'})
      this.setData({zanIcon:'thumb-circle'})
    }else{
      this.setData({action2:'add'})
      this.setData({zanIcon:'thumb-circle-o'})
    }
  },
  btn(){
    console.log(11);
  },
  // 分享
  onShareAppMessage: function () {
    console.log(11);
    return {
      title: '分享标题',
      path: '/pkgArticle/pages/detail/detail',
    }
  },


  async getNewData(id){
    const res = await wx.http.get(`/index/show?id=${id}`)
    this.setData({recommendData:res.data.recommend})
    this.setData({infoData:res.data.info})
    this.setData({date:date.formatTime(this.data.infoData.create_date,'yy/mm/dd')})
  }
})